package com.ruoyi.common.rabbit.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;

/**
 * @ClassName RabbitMQConfig
 * @Description TODO
 * @Author CnYuu
 * @Date 2025年01月08日 20:37
 * @Version 1.0
 */
public class RabbitMQConfig {
    //交换机名称
    public static final String ORDER_TOPIC_EXCHANGE = "order_topic_exchange";
    //队列名称
    public static final String ORDER_QUEUE_STATEMENT = "order_queue_statement";
    public static final String ORDER_QUEUE_SHOP = "order_queue_shop";
    public static final String DRAWAL_QUEUE = "drawal_queue";
    public static final String DRAWAL_QUEUE_SHOP = "drawal_queue_shop";

    //声明交换机
    @Bean("orderTopicExchange")
    public Exchange topicExchange(){
        return ExchangeBuilder.topicExchange(ORDER_TOPIC_EXCHANGE).durable(true).build();
    }

    //声明队列--支出明细
    @Bean("orderQueueStatement")
    public Queue itemQueue(){
        return QueueBuilder.durable(ORDER_QUEUE_STATEMENT).build();
    }
    //声明队列--商家金额收入
    @Bean("orderQueueShop")
    public Queue shopMoneyQueue(){
        return QueueBuilder.durable(ORDER_QUEUE_SHOP).build();
    }
    //声明队列--提现明细
    @Bean("drawalQueue")
    public Queue drawalQueue(){
        return QueueBuilder.durable(DRAWAL_QUEUE).build();
    }
    //声明队列--商家金额支出
    @Bean("drawalQueueShop")
    public Queue drawalQueueShop(){
        return QueueBuilder.durable(DRAWAL_QUEUE_SHOP).build();
    }

    //绑定队列和交换机
    @Bean
    public Binding orderQueueStatementBinding(
            @Qualifier("orderQueueStatement") Queue queue,
            @Qualifier("orderTopicExchange") Exchange exchange
    ){
        return BindingBuilder.bind(queue).to(exchange).with("order.insert.#").noargs();
    }

    @Bean
    public Binding itemQueueExchange(
            @Qualifier("orderQueueShop") Queue queue,
            @Qualifier("orderTopicExchange") Exchange exchange
    ){
        return BindingBuilder.bind(queue).to(exchange).with("order.insert.#").noargs();
    }

    @Bean
    public Binding drawalQueueExchange(
            @Qualifier("drawalQueue") Queue queue,
            @Qualifier("orderTopicExchange") Exchange exchange
    ){
        return BindingBuilder.bind(queue).to(exchange).with("drawal.insert.#").noargs();
    }

    @Bean
    public Binding drawalQueueShopExchange(
            @Qualifier("drawalQueueShop") Queue queue,
            @Qualifier("orderTopicExchange") Exchange exchange
    ){
        return BindingBuilder.bind(queue).to(exchange).with("drawal.insert.#").noargs();
    }
}
